package com.example.lifeData;

import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.SavedStateHandle;
import androidx.lifecycle.ViewModel;

public class ViewModelWithLiveData extends ViewModel {
    public SavedStateHandle handle;


    public ViewModelWithLiveData(SavedStateHandle handle){
        this.handle = handle;
    }

    public MutableLiveData<Integer> getLikedNumber() {
        if(!handle.contains(MainActivity.KEY_NUMBER)){
            handle.set(MainActivity.KEY_NUMBER,0);
        }
        return  handle.getLiveData(MainActivity.KEY_NUMBER);

    }

    public void addLikedNumber(int n){
        getLikedNumber().setValue(getLikedNumber().getValue()+n);
    }

}
